package JUC;

import java.beans.Customizer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

public class FunctionDemo {

    public static void main(String[] args) {
        /**
         * 函数型接口
         */
        Function<String, Integer> function = new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                return s.length();
            }
        };

        Function<String, Integer> function1 = s -> {
            return s.length();
        };


        System.out.println(function1.apply("hello"));

        /**
         * 消费型接口
         */
        Consumer<String> consumer = s -> {
            System.out.println(s);
        };

        /**
         * 供给型接口
         */

        consumer.accept("hello world!");

        Supplier<String> supplier = () -> {
            return "hello java";
        };
        System.out.println(supplier.get());

        Predicate<String> predicate = s -> {
            return s.isEmpty();
        };

        System.out.println(predicate.test("hello lzx"));
        System.out.println(predicate.test(""));

    }
}
